package tools;

import impl.AgentRef;

import java.util.ArrayList;
import java.util.Vector;

public class Fragment {
	private FragmentState currentState;
	private String id;
	private int criticity;
	private int processNumber;
	private ArrayList<MMME> requiredMMME;
	private ArrayList<MMME> providedMMME;
	
	public Fragment( ArrayList<MMME> _requiredMMME, ArrayList<MMME> _providedMMME, String _id, FragmentState state, int _criticity, int _processNumber){
		//Debug.println("state " +state );
		setCurrentState(state);
		//Debug.println("criticality " +_criticity );
		setCriticity(_criticity);
		//Debug.println("process " +_processNumber );
		setProcessNumber(_processNumber);
		//Debug.println("id " +_id );
		setId(_id);
		if(_requiredMMME==null){
			Debug.println(getId()+" : fragment without required mmme");
		}
		else
			requiredMMME=new ArrayList<MMME>(_requiredMMME);
		providedMMME=new ArrayList<MMME>(_providedMMME);
	}

	public synchronized void setCriticity(int criticity) {
		this.criticity = criticity;
	}

	public int getCriticity() {
		return criticity;
	}

	public  synchronized void setProcessNumber(int processNumber) {
		this.processNumber = processNumber;
	}

	public int getProcessNumber() {
		return processNumber;
	}

	public synchronized void setCurrentState(FragmentState currentState) {
		this.currentState = currentState;
	}

	public FragmentState getCurrentState() {
		return currentState;
	}
	
	public synchronized void setFragment(FragmentState state, int _criticity, int _processNumber){
		setCurrentState(state);
		setCriticity(_criticity);
		setProcessNumber(_processNumber);
	}

	public synchronized void setId(String id) {
		this.id = id;
	}

	public String getId() {
		return id;
	}
	
	public synchronized void setElements(ArrayList<MMME> _requiredMMME, ArrayList<MMME> _providedMMME){
		requiredMMME=new ArrayList<MMME>(_requiredMMME);
		providedMMME=new ArrayList<MMME>(_providedMMME);
	}
	
	public Vector<String> getRequiredElements() {
		// TODO Auto-generated method stub
		Vector<String> elements=new Vector<String>();
		for (int i=0; i<requiredMMME.size();i++)
			elements.add(requiredMMME.get(i).getID());
		return elements;
	}

}
